<?php
Class Retaurantcategories extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->data['controller'] = 'retaurantcategories';
        $this->load->model('Mretaurantcategories');
    }
    
    public function categoriesretaurant()
    {
        
        $this->data['id_active'] = $this->getParamUri(4,1);
        $this->load->library('pagination');
        $config['per_page'] = 10;
        $this->data['page'] = $this->data['pageCurrent'] = $this->getParamUri(4,1);
        $offset = (($this->getParamUri(4,1) - 1) * $config['per_page']) > 0 ? (($this->getParamUri(4,1) - 1) * $config['per_page']) : 0;
        $data = $this->Mretaurantcategories->getRetaurantCategoriesDB($config['per_page'],$offset);
        $config['base_url'] = base_url($this->uri->segment(1).'/'.$this->uri->segment(2).'/'.'/'.$this->uri->segment(3).'/');
        $config['total_rows'] = $data['count'];
        $config['uri_segment'] = 4;
        $config['uri_segment_page'] = $this->getParamUri(4,1);
        $config['suffix'] = '.html';
        $this->pagination->initialize($config);
 
        $this->data['pageg'] = $this->data['page'] - 1 > 0 ? $this->data['page'] - 1 : 0;
        $this->data['data'] = $data['data'];
        //echo "<pre>"; die(print_r($this->data['data']));

        $this->load->library('form_validation');
        $this->form_validation->set_rules('check-delete', 'Mục cần xóa', 'required');
        
        if($this->form_validation->run() === TRUE)
        {
            $idArray = $this->getParamArray('checkboxs');
            $run = $this->Mretaurantcategories->deleteRetaurantCategoriesDB($idArray);
            if(intval($run) == 200)
            {
                die('<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><script>/*alert("Xóa thành công");*/window.location="'.$this->data['baseurl'].'manage/retaurant/categories";</script>');
            }
        }
        
        $this->data['action'] = __FUNCTION__;
        $this->load->view('template/layout', $this->data);
    }
    
    public function addcategories()
    {
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('title', 'Tên quốc gia', 'required');
        
        if($this->form_validation->run() === TRUE)
        {
            $run = $this->Mretaurantcategories->addRetaurantCategoriesDb($this->session->userdata('admin_id'));
            if($run == 200)
            {
                die('<meta charset="utf-8"><script>alert("Thêm thành công");window.location.href="'.$this->data['baseurl'].'manage/zone/country.html";</script>');
            }
        }
        $this->data['action'] = 'addcategories';
        $this->load->view('template/layout', $this->data);
    }
    
    public function editcategories()
    {
        $this->load->library('form_validation');
        $this->form_validation->set_rules('title', 'Tên quốc gia', 'required');
        
        $this->data['id'] = $this->getParamUri(4,1);
        $this->data['data'] = $this->Mretaurantcategories->getRetaurantCategoriesDetailDB($this->data['id']);
        
        if($this->form_validation->run() === TRUE)
        {
            $run = $this->Mzone->editRetaurantCategoriesDb($this->session->userdata('admin_id'), $this->data['id']);
            if($run == 200)
            {
                die('<meta charset="utf-8"><script>alert("Lưu thành công");window.location.href="'.$this->data['baseurl'].'manage/zone/country.html";</script>');
            }
        }
        $this->data['action'] = 'editcategories';
        $this->load->view('template/layout', $this->data);
    }
    
    public function deletecategories()
    {
        $idArray = $this->getParamUri(4,1);
        $run = $this->Mretaurantcategories->deleteRetaurantCategoriesDB($idArray);
        if(intval($run) == 200)
        {
            die('<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><script>/*alert("Xóa thành công");*/window.location="'.$this->data['baseurl'].'manage/zone/country";</script>');
        }
    }
}